﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace Data.Comic
{
    public class ComicRepos
    {
         private ComicEntities db = new ComicEntities();
        public IEnumerable<Comic> GetListTop(int size, int typeView)
        {
             
                return db.Comic.OrderByDescending(e => e.Update).Take(size).ToList();
             
        }
        public Comic Get(string Slug)
        {
             
                return db.Comic.Where(c => c.Slug == Slug).FirstOrDefault();
            
        }
        public Comic Get(int Id)
        {
           
                return db.Comic.Where(c => c.Id == Id).FirstOrDefault();
           
        }
        public IEnumerable<Chapter> ListChapter(int ComicId)
        {
             
                return db.Chapter.Where(e => e.ComicId == ComicId).ToList();
            
        }
        public Chapter GetChapter(int Id)
        {
             
                return db.Chapter.Where(e => e.Id == Id).FirstOrDefault();
            
        }

        public IEnumerable<Pages> ListPage(int ChapterId)
        {
                return db.Pages.Where(e => e.ChapterId == ChapterId).OrderBy(e => e.Index).ToList();
             
        }
        public Pages GetPage(int Id)
        {
            
                return db.Pages.Where(e => e.Id == Id).FirstOrDefault();
             
        }

        public IEnumerable<ComicGenre> ListComicGenre(int ComicId)
        {
            
                return db.ComicGenre.Where(e => e.ComicId == ComicId).ToList();
            
        }
        public IEnumerable<Genre> ListGenre()
        {
              
                return db.Genre.ToList();
             
        }

        //public Dictionary<string, int> GetPopularTags(int? amountToTake)
        //{
        //    amountToTake = amountToTake ?? int.MaxValue;
        //    var tags = _context.TopicTag
        //        .Include(x => x.Topics.Count)
        //        .OrderByDescending(x => x.Topics.Count())
        //        .Take((int)amountToTake)
        //        .Select(s => new { TopicCount = s.Topics.Count(), TopicName = s.Tag })
        //        .Where(x => x.TopicCount > 0)
        //        .OrderByDescending(s => s.TopicCount).ToList();

        //    return tags.ToDictionary(tag => tag.TopicName, tag => tag.TopicCount);
        //}

        //public Genre GetGenre(int Id)
        //{
        //    using (ComicEntities db = new ComicEntities())
        //    {
        //        return db.Pages.Where(e => e.Id == Id).FirstOrDefault();
        //    }
        //}
        
    }
    public class ChapterView
    {

        public Comic comic { get; set; }
        public Chapter chapter { get; set; }
        public IEnumerable<Pages> listPage { get; set; }
        public IEnumerable<Chapter> listChapter { get; set; }
        public int TotalChapter { get; set; }
        public int TotalPage { get; set; }
    }
    public class ComicView
    {
        public Comic comic { get; set; }
        public IEnumerable<Chapter> listChapter { get; set; }
        public int TotalChapter { get; set; }
        public IEnumerable<ComicGenre> ListComicGenre { get; set; }
    } 
}